package com.lndsnx.ai.controller;

import com.lndsnx.ai.tool.TimeTools;
import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/ai/tool")
public class ToolController {

    @Resource
    private ChatClient chatClient;

    /**
     * No Tool
     */
    @GetMapping("/chat")
    public String chat(@RequestParam(value = "query", defaultValue = "请告诉我现在北京时间几点了？") String query) {
        return chatClient.prompt()
                .user(query)
                .call().content();
    }

    /**
     * Methods as Tools
     */
    @GetMapping("/chat/method")
    public String tool(@RequestParam(value = "query", defaultValue = "请告诉我现在北京时间几点了？") String query) {
        return chatClient.prompt()
                .user(query)
                .tools(new TimeTools())
                .call().content();
    }

    /**
     * Methods as Tools
     */
    @GetMapping("/chat/fc")
    public String fc(@RequestParam(value = "query", defaultValue = "请告诉我现在北京时间几点了？") String query) {
        return chatClient.prompt()
                .user(query)
                .toolNames("getTimeByZoneId")
                .call().content();
    }
}
